package com.transino.bop.domain;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.kanas.framework.support.AbstractModel;

@XmlRootElement(name = "category")
public class Category extends AbstractModel implements Cloneable,Comparable<Category> {

	private static final long serialVersionUID = 1L;
	
	private String id;
	private String name;
	private String defaultShow;
	private Integer index;
	private Category SuperCateogry;
	private List<Category> subCategories;
	private List<Entity> entities;
	
	@XmlAttribute(name = "id")
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	@XmlAttribute(name = "name")
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	@XmlAttribute(name = "index")
	public Integer getIndex() {
		return index;
	}
	
	public void setIndex(Integer index) {
		this.index = index;
	}

	public Category getSuperCateogry() {
		return SuperCateogry;
	}

	public void setSuperCateogry(Category superCateogry) {
		SuperCateogry = superCateogry;
	}

	@XmlElement(name = "category")
	public List<Category> getSubCategories() {
		if(subCategories == null)subCategories = new ArrayList<Category>();
		return subCategories;
	}

	public void setSubCategories(List<Category> subCategories) {
		this.subCategories = subCategories;
	}

	public List<Entity> getEntities() {
		if(entities == null) entities = new ArrayList<Entity>();
		return entities;
	}

	public void setEntities(List<Entity> entities) {
		this.entities = entities;
	}

	@XmlAttribute(name = "defaultShow")
	public String getDefaultShow() {
		return defaultShow;
	}

	public void setDefaultShow(String defaultShow) {
		this.defaultShow = defaultShow;
	}

	@Override
	public int compareTo(Category o) {
		if(this.index==null || o.getIndex()==null) {
			return 1;
		}else {
			return this.index - o.getIndex();
		}
	}

	@Override
	public String toIdString() {
		return this.id;
	}
	
}
